package com.bj58.mis.apm.server.statistics.dto.cube;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * @author: zhangfx
 * @create: 2018-06-20 17:06
 **/
@ApiModel(description = "Cube设计信息")
@Data
public class CubeDesign {
    @ApiModelProperty(value = "Cube ID")
    private String cubeId;

    @ApiModelProperty(value = "维度数据")
    private List<CubeDimensions> dimensions;

    @ApiModelProperty(value = "聚合组数据")
    private List<CubeGroup> groups;

    @ApiModelProperty(value = "度量数据")
    private List<CubeMeasure> measures;


    @ApiModelProperty(value = "Cube数据分区设置")
    private CubePartitionConfig partitionConfig;

    @ApiModelProperty(value = "Cube刷新设置")
    private CubeMergeConfig mergeConfig;


    @ApiModelProperty(value = "维度数据按表聚合")
    public List<DimensionsGroup> getDimensionsGroups(){
        Map<String, List<CubeDimensions>> result = new HashMap<>();
        if(this.dimensions!=null){
            this.dimensions.forEach(item -> {
                if(!result.containsKey(item.getTable())){
                    result.put(item.getTable(), new ArrayList<>());
                }
                result.get(item.getTable()).add(item);
            });
        }
        return result.entrySet().stream().map(entry -> new DimensionsGroup(entry.getKey(), entry.getValue())).collect(Collectors.toList());
    }

}